<template>
	<view class="img-box-all">
		<!-- <myLoading></myLoading> -->
		<view class="text-box">
			<image class="text-box-icon" src="https://image.nanjingtouyang.com/touy/2024/06/18/9e5da196e0a84e29b1677ed34d5eea9f.png" mode=""></image>
			<view class="text-box-txt">个人资料</view>
		</view>
		
		<button class="img_box" open-type="chooseAvatar" @chooseavatar="onChooseAvatar">
			<image class="img_box-avatar" :src="imageUrl"></image>
		</button>
		
		<view class="icon-text">为提升用户体验，请使用真实头像</view>
		
		<view class="set-box">
			<view class="set-box-item">
				<view class="set-box-item-title">教练类型</view>
				<view class="set-box-item-input">
					<span v-if="serviceType == 1">健身</span>
					<span v-else>瑜伽</span>
					
				</view>
			</view>
			
			<view class="set-box-item">
				<view class="set-box-item-title">姓名</view>
				<view class="set-box-item-input">
					<input type="text" class="set-input" placeholder="请填写姓名" v-model="nick_name"  maxlength="10" @blur="inputUserName" />
					<view class="set-icon-box">
						<image class="set-icon" src="https://image.nanjingtouyang.com/touy/2023/08/2023081713403034403.png" ></image>
					</view>
				</view>
			</view>
			<view class="set-box-item">
				<view class="set-box-item-title">性别</view>
				<view class="set-box-item-input">
					<picker class="set-input" :value="sex" :range="sexList" :range-key="'name'" @change="changePickerSex($event)">
						<view>{{ sexName }}</view>
					</picker>
					<view class="set-icon-box">
						<image class="set-icon" src="https://image.nanjingtouyang.com/touy/2023/11/14/296ec5eba2f24c499e4080aac46343c6.png" ></image>
					</view>
				</view>
			</view>
			<view class="set-box-item">
				<view class="set-box-item-title">出生日期</view>
				<view class="set-box-item-input">
					<picker class="set-input" mode="date" :value="birthday" :start="startDate" :end="endDate" @change="bindDateChange">
						<view @click="dateShow = true" class="view-input">{{ birthday }}</view>
					</picker>
					<view class="set-icon-box">
						<image class="set-icon" src="https://image.nanjingtouyang.com/touy/2023/11/14/296ec5eba2f24c499e4080aac46343c6.png" ></image>
					</view>
				</view>
			</view>
			<view class="set-box-item">
				<view class="set-box-item-title">手机号</view>
				<view class="set-box-item-input">
					<view class="set-input">
						<h1>{{phone}}</h1>
					</view>
				</view>
			</view>
			
			<view class="set-box-item">
				<view class="set-box-item-title">地址</view>
				<view class="set-box-item-input">
					<view class="choose-area"  @click="toChooseLocation">{{ address }}</view>
					<view class="set-icon-box">
						<image class="set-icon" src="https://image.nanjingtouyang.com/touy/2023/11/14/296ec5eba2f24c499e4080aac46343c6.png" ></image>
					</view>
				</view>
			</view>
			<view class="set-box-item">
				<view class="set-box-item-title">从业年限</view>
				<view class="set-box-item-input">
					<view class="input-flex">
						<input type="text" class="flex-input" placeholder="请输入" v-model="years"  maxlength="2" />
						<view class="flex-text">年</view>
					</view>
					
					<view class="set-icon-box">
						<image class="set-icon" src="https://image.nanjingtouyang.com/touy/2023/08/2023081713403034403.png" ></image>
					</view>
				</view>
			</view>
			<view class="set-box-item">
				<view class="set-box-item-title">个人标签</view>
				<view class="set-box-item-input">
					<view class="choose-area" @click="toChooseLabel">{{ label }}</view>
					
					<view class="set-icon-box">
						<image class="set-icon" src="https://image.nanjingtouyang.com/touy/2023/08/2023081713403034403.png" ></image>
					</view>
				</view>
			</view>
			<view class="set-box-item">
				<view class="set-box-item-title">服务时长</view>
				<view class="set-box-item-input">
					<view class="choose-area" @click="toChooseTime">{{ time }}</view>
					
					<view class="set-icon-box">
						<image class="set-icon" src="https://image.nanjingtouyang.com/touy/2023/08/2023081713403034403.png" ></image>
					</view>
				</view>
			</view>
			
			<view class="set-box-item">
				<view class="set-box-item-title">1v1单价</view>
				<view class="set-box-item-input">
					<picker class="set-input" :value="moneyOne" :range="priceList" :range-key="'dictLabel'" @change="changePickerMoney($event)">
						<view>{{ moneyOne }}</view>
					</picker>
					<view class="set-icon-box">
						<image class="set-icon" src="https://image.nanjingtouyang.com/touy/2023/11/14/296ec5eba2f24c499e4080aac46343c6.png" ></image>
					</view>
				</view>
			</view>
			
			<view class="set-box-item" v-if="serviceType == 1">
				<view class="set-box-item-title">1v2单价</view>
				<view class="set-box-item-input">
					<view class="input-flex">
						<input disabled="false" type="text" class="flex-input" placeholder="请输入" v-model="money"  maxlength="4" />
						<!-- <view class="flex-text">元</view> -->
					</view>
					
					<view class="set-icon-box">
						<image class="set-icon" src="https://image.nanjingtouyang.com/touy/2023/08/2023081713403034403.png" ></image>
					</view>
				</view>
			</view>
			
			<!-- <view class="set-box-item">
				<view class="set-box-item-title">服务单价</view>
				<view class="set-box-item-input">
					<view class="input-flex">
						<input type="text" class="flex-input" placeholder="请输入" v-model="money"  maxlength="4" />
						<view class="flex-text">元</view>
					</view>
					
					<view class="set-icon-box">
						<image class="set-icon" src="https://image.nanjingtouyang.com/touy/2023/08/2023081713403034403.png" ></image>
					</view>
				</view>
			</view> -->
			
			<view class="set-box-item">
				<view class="set-box-item-title">简介</view>
				<view class="set_box-item-text">
					<textarea class="textarea-input" placeholder="介绍一下自己吧~" v-model="desc"  maxlength="1000" @blur="inputDesc"/>
				</view>
			</view>
			
			<view class="image-upload-item">
				<view class="set-box-item-title">个人风采<span style="font-size: 26rpx;">（长按可调整图片顺序）</span></view>
				<shmily-drag-image v-model="imageArr"></shmily-drag-image>
			</view>
			
			
			<!-- <view class="image-upload-item-two">
				<view class="set-box-item-title">资质证明</view>
				<view class="set-box-image">
					<image class="set-box-image-item" v-for="(item, index) in imageArrTwo" :key="index" :src="item" mode="aspectFill"></image>
				</view>
			</view> -->
		</view>
		
		<view class="item-line"></view>
		<view class="set-box" style="padding-bottom: 180rpx;">
			
			<view class="text-box" style="padding: 0rpx !important;">
				<image class="text-box-icon" src="https://image.nanjingtouyang.com/touy/2024/06/18/8937a12819e04ecfaa474d90ca418795.png" mode=""></image>
				<view class="text-box-txt">教练资质</view>
			</view>
			
			<view class="image-upload-item-two">
				<view class="set-box-item-title">资质证明(例：教练资格证）</view>
				<shmily-drag-image v-model="imageArrTwo"></shmily-drag-image>
			</view>
		</view>
		
		
		<view class="buttom-buttons">
			<view class="buttons-baoming" v-if="uploadTrue==false" @click="save">提交</view>
			<view class="buttons-baoming" v-else>头像上传中</view>
		</view>
		
		<u-popup v-model="labelCoverShow" mode="bottom" border-radius="30" closeable="true">
			<view>
				<!-- 个人标签 -->
				<view class="choose-type-box">
					<view class="type-box-title">个人标签</view>
					<scroll-view scroll-y="true" class="scorll-view" >
						<view class="scorll-view-boxs">
							
							<view 
								v-for="(item, index) in labelAllList" :key="index" 
								:class="item.active == true ? 'scorll-view-item scorll-view-item-active' : 'scorll-view-item'" 
								@click="chooseLabelItem(item, index)"
								>
								
									{{ item.dictLabel }}
								
								
							</view>
						</view>
					</scroll-view>
					<view class="confirm-button">
						<view class="button-item" @click="closeLabelCover">
							确认
						</view>
					</view>
				</view>
			</view>
		</u-popup>
		
		<u-popup v-model="timeCoverShow" mode="bottom" border-radius="30" closeable="true">
			<view>
				<!-- 选择展示权限 -->
				<view class="choose-type-box" >
					<view class="type-box-title">服务时长</view>
					<view 
						v-for="(item, index) in timeList" 
						:class="item.dictValue == chooseTimeId ? 'type-box-items type-box-items-active' : 'type-box-items'" 
						:key="item.dictValue"
						@click="chooseTime(item)">
						{{ item.dictLabel }}
					</view>
					<view class="type-box-bottom">
						
					</view>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import { applySp } from "@/api/mine.js"
	import QQMapWX from "@/common/qqmap-wx-jssdk.js"
	import { getAreaCode, getCommenKey, replaceWord  } from "@/api/public.js"
	import { baseUrl } from '@/utils/request.js'
	import { getMySpInfo } from '@/api/mine.js'
	export default {
		data(){
			const currentDate = this.getDate({
				format: true
			})
			return{
				uploadTrue: false,
				date: currentDate,
				sexList: [
					{
						id: 0,
						name: '女'
					},
					{
						id: 1,
						name: '男'
					}
				],
				nick_name: '',
				sex: '',
				birthday: '请选择生日',
				phone: '',
				desc: '',
				sexName: '请选择性别', //性别显示
				dateShow: false,
				imageUrl: '',
				address: '将影响与用户、场馆、匹配的定位',
				lat: '',
				lon: '',
				areaCode: '',
				cityCode: '',
				years: '',
				label: '请选择',
				labelAllList: [],
				chooseLabelId: [],
				chooseLabelName: [],
				labelCoverShow: false,
				time: '请选择',
				timeCoverShow: false,
				timeList: [],
				chooseTimeId: '',
				money: '',
				
				imageArr: [],
				imageArrUpload: [],
				length: '',
				index: '',
				updateTrue: '',
				
				imageArrTwo: [],
				imageArrUploadTwo: [],
				lengthTwo: '',
				indexTwo: '',
				updateTrueTwo: '',
				editId: '',
				isEdit: false,
				status: '',
				
				priceList: [],
				moneyOne:'请选择',
				serviceType: ''
				
			}
		},
		onLoad(options){
			// this.getTypeKeys()
			this.getUserInfo()
			// this.getUserInfoItem()
			// this.userId= uni.getStorageSync('userId')
			this.phone = uni.getStorageSync('spPhone')
			this.imageUrl = 'https://image.nanjingtouyang.com/touy/2024/05/20/b528001914de4cfd8d6a619a413b3f16.png'
			
			
			if(options.isEdit == 'true') {
				this.isEdit = true
				// this.getUserInfo()
			}
		},
		computed: {
				startDate() {
					return this.getDate('start');
				},
				endDate() {
					return this.getDate('end');
				},
				imageArrLength() {
					return this.imageArr.length
				}
		},
		methods:{
			getUserInfo() {
				getMySpInfo().then(res => {
					this.editId = res.data.data.spId
					res.data.data.showPic = res.data.data.showPic.split(',')
					res.data.data.certPic = res.data.data.certPic.split(',')
					
					this.imageArr = []
					res.data.data.showPic.forEach(item => {
						this.imageArr.push(item)
					})
					
					
					// this.imageArrTwo = res.data.data.certPic
					// console.log(11)
					// console.log(this.imageArrTwo)
					this.imageArrTwo = []
					res.data.data.certPic.forEach(item => {
						this.imageArrTwo.push(item)
					})
					
					this.imageUrl = res.data.data.spAvatar
					this.nick_name = res.data.data.spName
					this.sex = res.data.data.sex
					this.birthday = res.data.data.birthDate
					this.address = res.data.data.addr
					this.lat = res.data.data.latitude
					this.lon = res.data.data.longitude
					this.areaCode = res.data.data.areaCode
					this.cityCode = res.data.data.cityCode
					this.years = res.data.data.workYears
					this.chooseLabelId = res.data.data.tagList
					this.label = res.data.data.tagLabel
					this.status = res.data.data.status
					this.serviceType = res.data.data.serviceType
					
					if(this.sex == 0) {
						this.sexName = '女'
					} else {
						this.sexName = '男'
					}
					
					this.labelAllList.forEach(item => {
						this.chooseLabelId.forEach(items => {
							if(items == item.dictValue) {
								item.active = true
							}
							
						})
						
					})
					this.chooseTimeId = res.data.data.serviceTime
					this.time = res.data.data.serviceTime + '分钟'
					this.money = res.data.data.price2
					this.moneyOne = res.data.data.price
					this.desc = res.data.data.spDesc
					
					this.getTypeKeys()
					
					
				})
			},
			getTypeKeys() {
				getCommenKey('t_sp_tag').then(res => {
					this.labelAllList = res.data.data
					this.labelAllList.forEach(item => {
						item.active = false
					})
				})
				
				getCommenKey('t_sp_service_time').then(res => {
					this.timeList = res.data.data
					
				})
				
				console.log(this.serviceType)
				if(this.serviceType == 1) {
					getCommenKey('t_sp_price_1').then(res => {
						this.priceList = res.data.data
					})
				} else {
					getCommenKey('t_sp_price_2').then(res => {
						this.priceList = res.data.data
					})
				}
				// getCommenKey('t_sp_price_1').then(res => {
				// 	this.priceList = res.data.data
					
				// })
				
			},
			toChooseLabel() {
				this.labelCoverShow = true
			},
			closeLabelCover() {
				this.labelCoverShow = false
			},
			chooseLabelItem(item, index) {
				if(this.chooseLabelId.length > 4 && item.active == false) {
					uni.showToast({
						title:'最多选择5个标签哦',
						icon:'none'
					})
					return
				}
	
				let obj = this.labelAllList[index]
				let num = this.labelAllList[index].active
				this.$delete(obj, 'active')
				this.$set(obj, "active", !num)
				
				let chooseList = []
				let chooseName = []
				this.labelAllList.forEach(item => {
					if(item.active == true) {
						chooseList.push(item.dictValue)
						chooseName.push(item.dictLabel)
					}
				})
				this.chooseLabelId = chooseList
				this.chooseLabelName = chooseName
				this.label = this.chooseLabelName.join(',')
			},
			chooseTime(item) {
				this.chooseTimeId = item.dictValue
				this.time = item.dictLabel
				this.timeCoverShow = false
			},
			toChooseTime() {
				this.timeCoverShow = true
			},
			inputUserName() {
				replaceWord({
					value: this.nick_name
				}).then(res => {
					this.nick_name = res.data.data.value
				})
			},
			inputDesc() {
				replaceWord({
					value: this.desc
				}).then(res => {
					this.desc = res.data.data.value
				})
			},
			changePickerSex(e) {
				this.sex = e.detail.value
				this.sexName = this.sexList[e.detail.value].name
			},
			bindDateChange(e) {
				this.birthday = e.detail.value
			},
			onChooseAvatar(e) {
				this.uploadTrue = true
				this.imageUrl = e.detail.avatarUrl
				uni.uploadFile({
					url: baseUrl + '/file/upload', //上传图片api
					filePath: e.detail.avatarUrl,
					name: 'file',
					header: {
						"Authorization":uni.getStorageSync("spToken"),
						"Terminal-Type":'applet',
						"Area-code":uni.getStorageSync("City_Code")
					},
					success: (res) => {
						let data =  JSON.parse(res.data) 
						this.imageUrl = data.data.url
						// uni.showLoading({
						//   title: 'Loading...',
						// })
						// uni.showToast({
						// 	title:'头像上传完成，请点击保存',
						// 	icon:'none'
						// })
						this.uploadTrue = false
					}
				})
			},
			changePickerMoney(e) {
				this.moneyOne = this.priceList[e.detail.value].dictValue
				this.money = this.priceList[e.detail.value].ext1
			},
			//保存
			save(){
				
				if(this.nick_name == '') {
					uni.showToast({
						title:'请填写姓名',
						icon:'none'
					})
					return
				}
				if(this.sex == '') {
					uni.showToast({
						title:'请选择性别',
						icon:'none'
					})
					return
				}
				if(this.birthday == '请选择生日') {
					uni.showToast({
						title:'请选择生日',
						icon:'none'
					})
					return
				}
				if(this.address == '将影响与用户、场馆、匹配的定位') {
					uni.showToast({
						title:'请选择地址',
						icon:'none'
					})
					return
				}
				
				if(this.years == '') {
					uni.showToast({
						title:'请填写从业年限',
						icon:'none'
					})
					return
				}
				if(this.years !== '') {
					let isNumber = !isNaN(this.years)
					if(isNumber == false) {
						uni.showToast({
							title:'从业年限只能填写数字',
							icon:'none'
						})
						return
					}	
				}
				
				if(this.years !== '') {
					var r = /^\+?[1-9][0-9]*$/;
					if(r.test(this.years) == false) {
						uni.showToast({
							title:'从业年限只能为正整数',
							icon:'none'
						})
						return
					}	
				}
				
				if(this.years <= 0) {
					uni.showToast({
						title:'从业年限必须大于0',
						icon:'none'
					})
					return
				}
				
				
				if(this.label == '请选择') {
					uni.showToast({
						title:'请选择个人标签',
						icon:'none'
					})
					return
				}
				
				if(this.time == '请选择') {
					uni.showToast({
						title:'请选择服务时长',
						icon:'none'
					})
					return
				}
				
				// if(this.money == '') {
				// 	uni.showToast({
				// 		title:'请填写服务单价',
				// 		icon:'none'
				// 	})
				// 	return
				// }
				if(this.moneyOne == '请选择') {
					uni.showToast({
						title:'请选择价格',
						icon:'none'
					})
					return
				}
				
				// if(this.money !== '') {
				// 	let isNumber = !isNaN(this.money)
				// 	if(isNumber == false) {
				// 		uni.showToast({
				// 			title:'服务单价只能填写数字',
				// 			icon:'none'
				// 		})
				// 		return
				// 	}	
				// }
				
				// if(this.money <= 0) {
				// 	uni.showToast({
				// 		title:'服务单价必须大于0',
				// 		icon:'none'
				// 	})
				// 	return
				// }
				
				if(this.imageArr == '') {
					uni.showToast({
						title:'请添加个人风采图片',
						icon:'none'
					})
					return
				}
				
				if(this.imageArrTwo == '') {
					uni.showToast({
						title:'请添加资质证明图片',
						icon:'none'
					})
					return
				}
				
				// this.upload()
				this.length = this.imageArr.length
				this.index = 0
				this.updateTrue = true
				uni.showLoading({
				  title: 'Loading...',
				})
				
				this.uploadFileNew()
					
			},
			uploadFileNew() {
				if(this.imageArr[this.index].search("https://image.nanjingtouyang.com/") !== -1) {
					// 编辑的时候
					this.imageArrUpload.push(this.imageArr[this.index].slice(33))
					this.index ++
					if (this.index == this.length) {
						this.lengthTwo = this.imageArrTwo.length
						this.indexTwo = 0
						this.updateTrueTwo = true
						uni.showLoading({
						  title: 'Loading...',
						})
						this.uploadFileNewTwo()
						// this.edit()
						
					} else {
						this.uploadFileNew(this.imageArr.length)
					}
					
				} else {
					uni.uploadFile({
						url: baseUrl + '/file/upload',
						header: {
							"Authorization":uni.getStorageSync("spToken"),
							"Terminal-Type":'applet',
							"Area-code":uni.getStorageSync("City_Code")
						},
						filePath: this.imageArr[this.index],
						name: 'file',
						success: (res) => {
							let data =  JSON.parse(res.data)
							if(data.code == 200) {
								this.index ++
								this.imageArrUpload.push(data.data.url.slice(33))
							}
						},
						complete: () => {
							if (this.index == this.length) {
								this.lengthTwo = this.imageArrTwo.length
								this.indexTwo = 0
								this.updateTrueTwo = true
								uni.showLoading({
								  title: 'Loading...',
								})
								this.uploadFileNewTwo()
								// this.edit()
							} else { //递归调用
							  this.uploadFileNew(this.imageArr.length)
							}
						  },
					
					})
				}
				
			},
			uploadFileNewTwo() {
				
				if(this.imageArrTwo[this.indexTwo].search("https://image.nanjingtouyang.com/") !== -1) {
					// 编辑的时候
					this.imageArrUploadTwo.push(this.imageArrTwo[this.indexTwo].slice(33))
					this.indexTwo ++
					if (this.indexTwo == this.lengthTwo) {
						if(this.editId) {
							this.edit()
						} else {
							this.upload()
						}
						
					} else {
						this.uploadFileNewTwo(this.imageArrTwo.length)
					}
					
				} else {
					uni.uploadFile({
						url: baseUrl + '/file/upload',
						header: {
							"Authorization":uni.getStorageSync("spToken"),
							"Terminal-Type":'applet',
							"Area-code":uni.getStorageSync("City_Code")
						},
						filePath: this.imageArrTwo[this.indexTwo],
						name: 'file',
						success: (res) => {
							let data =  JSON.parse(res.data)
							if(data.code == 200) {
								this.indexTwo ++
								this.imageArrUploadTwo.push(data.data.url.slice(33))
							}
						},
						complete: () => {
							if (this.indexTwo == this.lengthTwo) {
								if(this.editId) {
									this.edit()
								} else {
									this.upload()
								}
							} else { //递归调用
							  this.uploadFileNewTwo(this.imageArrTwo.length)
							}
						  },
					
					})
				}
			},
			upload() {
				let newList = []
				this.imageArrUpload.forEach(item => {
					newList.push('https://image.nanjingtouyang.com/' + item)
				})
				let newList2 = []
				this.imageArrUploadTwo.forEach(item => {
					newList2.push('https://image.nanjingtouyang.com/' + item)
				})
				applySp({
					spAvatar: this.imageUrl,
					spName: this.nick_name,
					birthDate: this.birthday,
					contactPhone: this.phone,
					addr: this.address,
					sex: this.sex,
					latitude: this.lat,
					longitude: this.lon,
					areaCode: this.areaCode,
					cityCode: this.cityCode,
					workYears: this.years,
					tagList: this.chooseLabelId,
					serviceTime: this.chooseTimeId,
					price: this.moneyOne,
					price2: this.money,
					spDesc: this.desc,
					showPic: newList.toString(),
					certPic: newList2.toString(),
					status: this.status,
					serviceType: this.serviceType
					
				}).then(res => {
					if(res.data.code == 200) {
						uni.showToast({
							title:'修改成功',
							icon:'success'
						})
						setTimeout(()=>{
							uni.navigateBack()
						},1000)
					}else {
						uni.showToast({
							title:res.data.msg,
							icon:'none'
						})
						
						this.updateTrue = false
						this.imageArrUpload = []
						this.imageArrUploadTwo = []
					}
				})
				
			},
			edit() {
				
				let newList = []
				this.imageArrUpload.forEach(item => {
					newList.push('https://image.nanjingtouyang.com/' + item)
				})
				let newList2 = []
				this.imageArrUploadTwo.forEach(item => {
					newList2.push('https://image.nanjingtouyang.com/' + item)
				})
				console.log(newList2)
				applySp({
					spId: this.editId,
					spAvatar: this.imageUrl,
					spName: this.nick_name,
					birthDate: this.birthday,
					contactPhone: this.phone,
					addr: this.address,
					sex: this.sex,
					latitude: this.lat,
					longitude: this.lon,
					areaCode: this.areaCode,
					cityCode: this.cityCode,
					workYears: this.years,
					tagList: this.chooseLabelId,
					serviceTime: this.chooseTimeId,
					price: this.moneyOne,
					price2: this.money,
					spDesc: this.desc,
					showPic: newList.toString(),
					certPic: newList2.toString(),
					status: this.status,
					serviceType: this.serviceType
				}).then(res => {
					if(res.data.code == 200) {
						uni.showToast({
							title:'修改成功',
							icon:'success'
						})
						setTimeout(()=>{
							uni.navigateBack()
						},1000)
					}else {
						uni.showToast({
							title:res.data.msg,
							icon:'none'
						})
						
						this.updateTrue = false
						this.imageArrUpload = []
						this.imageArrUploadTwo = []
					}
				})
				
			},
			getDate(type) {
				const date = new Date();
				let year = date.getFullYear();
				let month = date.getMonth() + 1;
				let day = date.getDate();
				if (type === 'start') {
					year = year - 60;
				} else if (type === 'end') {
					year = year + 2;
				}
				month = month > 9 ? month : '0' + month;
				day = day > 9 ? day : '0' + day;
				return `${year}-${month}-${day}`;
			},
			toChooseLocation() {
				var that = this
				uni.chooseLocation({
					success: function (res) {
						that.address = res.name
						that.lat = res.latitude
						that.lon = res.longitude
						that.getCityCode()
					}
				})
			},
			getCityCode() {
				let location = {
					longitude: 0,
					latitude: 0,
				}
				var that = this
				// uni.getLocation({
				// 	type: "gcj02",
				// 	success(res) {
						location.longitude = that.lon
						location.latitude = that.lat
						// 腾讯地图Api
						const qqmapsdk = new QQMapWX({
							key: 'SBBBZ-CF3W4-ISNUN-KFKP2-FNFR2-AJFK5'
						})
						qqmapsdk.reverseGeocoder({
							location,
							sig:'g4szVHEVqnQqnj49rsmI7yewIJJPWDW',
							success(response) {
								let info = response.result
								
								// that.cityName = info.ad_info.city
								getAreaCode({
									provinceExtName: info.address_component.province,
									cityExtName: info.address_component.city,
									districtExtName: info.address_component.district,
									
								}).then(res => {
									that.areaCode = res.data.data.district
									that.cityCode = res.data.data.city
								})
							}
						})
				// 	}
				// })
			},
			// previewImg(index){
			// 	uni.previewImage({
			// 	   // 预览时，默认显示图片的索引
			// 	  current: index,
			// 	  // 所有图片 url 地址的数组
			// 	  urls: this.imageArr.map(x => x)
			// 	})
			// },
		}
	}
</script>

<style lang="scss">
	@import './set-detail.scss';
</style>